﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Tbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

namespace HKEA.CMS.Core.BLL.Tbl
{
    public class tblMediaRoomRelatedBLL
    {
        private ItblMediaRoomRelated IDAL;

        public tblMediaRoomRelatedBLL()
        {
            IDAL = DataAccess.CreateItblMediaRoomRelated();
        }

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static tblMediaRoomRelatedBLL GetInstance()
        {
            return new tblMediaRoomRelatedBLL();
        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="MediaUIDList">需要被关联的MediaUID集合</param>
        /// <param name="strCategory">类型</param>
        /// <param name="ToRelatedUID">被关联的UID eg.:CustBranchUID</param>
        /// <returns></returns>
        public int InsertList(List<int> MediaUIDList, string strCategory, int ToRelatedUID)
        {
            int ret = 0;
            if (MediaUIDList.Count > 0 && ToRelatedUID > 0)
            {
                try { ret = IDAL.InsertList(MediaUIDList, strCategory, ToRelatedUID); }
                catch (Exception er) { throw er; }
            }
            return ret;
        }
        public List<M_MediaRoomRelatedDetail> GetList(tblMediaRoom_Related ent, List<int> WithOutList)
        {
            List<M_MediaRoomRelatedDetail> list = new List<M_MediaRoomRelatedDetail>();
            if (ent != null)
            {
                try { list = IDAL.GetList(ent, WithOutList); }
                catch (Exception er) { throw; }
            }
            return list;
        }
        /// <summary>
        /// 批量修改；Item格式:RelatedUID_MediaRoomUID   注意:MediaRelatedUIDList、MediaUIDList必须一一对应
        /// </summary>
        /// <param name="MediaRelatedUIDList">需要被修改的MediaRelatedUID集合</param>
        /// <param name="strCategory">类型</param>
        /// <param name="MediaUIDList">需要被修改的 MediaUID集合</param>
        /// <returns></returns>
       
        public int UpdateList(List<string> strUIDList, string strCategory)
        {
            int ret = 0;
            List<int> RelatedUIDList = new List<int>();
            List<int> MediaUIDList = new List<int>();
            if (strUIDList.Count > 0)
            {
                foreach (var temp in strUIDList)
                {
                    string[] str = temp.Split('_');
                    if (str.Length ==2)
                    {
                        RelatedUIDList.Add(int.Parse(str[0]));
                        MediaUIDList.Add(int.Parse(str[1]));
                    }
                }
                if (RelatedUIDList.Count > 0 && RelatedUIDList.Count == MediaUIDList.Count)
                {
                    try { ret = IDAL.UpdateList(RelatedUIDList, strCategory, MediaUIDList); }
                    catch (Exception er) { throw er; }
                }
            }
            return ret;
        }

        /// <summary>
        /// 假删除—修改Deleted为 1；
        /// </summary>
        /// <param name="MediaRelatedUIDList">MediaRoomUID</param>
        /// <returns></returns>
        public int DeleteListFalse(List<int> MediaRelatedUIDList)
        {
            int ret = 0;
            if (MediaRelatedUIDList.Count > 0)
            {
                try { ret = IDAL.DeleteListFalse(MediaRelatedUIDList); }
                catch (Exception er) { throw er; }
            }
            return ret;
        }

        public tblMediaRoom_Related GetEntity(tblMediaRoom_Related ent)
        {
            return GetListByENT(ent).FirstOrDefault();
        }

        public List<tblMediaRoom_Related> GetListByENT(tblMediaRoom_Related ent)
        {
            List<tblMediaRoom_Related> list = new List<tblMediaRoom_Related>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 查询出App表中未标志为删除的tblMediaRoom_Related列表；
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<tblMediaRoom_Related> GetListWithOutAppDelByENT(tblMediaRoom_Related ent)
        {
            List<tblMediaRoom_Related> list = new List<tblMediaRoom_Related>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListWithOutAppDelByENT(ent);
                }
                catch (Exception er)
                { }
            }
            return list;
        }

        public List<Ext_MediaRoom> GetListWithMediaRoomByENT(tblMediaRoom_Related ent)
        {
            List<Ext_MediaRoom> list = new List<Ext_MediaRoom>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListWithMediaRoomByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public List<Ext_MediaRoom> GetListWithMediaRoomByENT(Ext_MediaRoom ent)
        {
            List<Ext_MediaRoom> list = new List<Ext_MediaRoom>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListWithMediaRoomByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public List<tblMediaRoom_Related> GetListByENT(tblMediaRoom_Related ent, PageParam param, string strPropertyName, string strOrderBy)
        {
            List<tblMediaRoom_Related> list = new List<tblMediaRoom_Related>();
            if (ent != null && param != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent, param, strPropertyName, strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public int GetCountByENT(tblMediaRoom_Related ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return ret;
        }

        public int InsertENT(tblMediaRoom_Related ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.InsertENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }

        public int UpdateENT(tblMediaRoom_Related ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }

        public int DeleteENT(tblMediaRoom_Related ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return ret;
        }

        
    }
}
